<?php

/**
 * @author thihien
 * @copyright 2011
 */

include_once('includes/general.php');
if(!tep_db_checkDb()) die('connect fail!');
//$maloaitintuc=$_GET['maloaitintuc'];
$sql='SELECT count(id) as count FROM `tbl_tin_tuc` where ma_loai_tin_tuc=1';
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=5;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;

$content='';
$sql4='select * from tbl_tin_tuc where ma_loai_tin_tuc=1 limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
/*-------------lay ten danh muc donvi nghien cuu*/
$sql3='select ten_loai_tin_tuc from tbl_loai_tin_tuc where id=1';
$kq3=tep_db_query($sql3);
$item2=tep_db_fetch_array($kq3);

$content.='<div id="center">
             <div class="tin_tuc_noi_bat">
                <div class="tieude_center"><h3>'.$item2['ten_loai_tin_tuc'].'</h3></div>';
    
    while($item=tep_db_fetch_array($kq4)){
         $content.='
         <div class="hienthi_tt">
                <div class="hinh_anh_dich_vu"><a href="?page=tintuc&matintuc='.$item['id'].'&maloaitintuc=1&mode=detail"><img  width="140" height="140" src="admincp/upload/'.$item['hinh_anh'].'"/></a></div>
                <div class="tt_dichvu_tieude"><a  href="?page=tintuc&matintuc='.$item['id'].'&maloaitintuc=1&mode=detail"> '.$item['ten_nghien_cuu'].'</a></div>
                <div class="mo_ta_ngan_gon_dich_vu">'.$item['mo_ta_ngan_gon'].'<br/>
                    <a href="?page=tintuc&matintuc='.$item['id'].'&maloaitintuc=1&mode=detail"><p>Chi Tiết...</p></a>
                </div>
           
        </div>';
   
    }
    $content.=' 
    <ul class="phantrang" id="phantrang1">';
         $content.='Trang:';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="?maloaitintuc=1&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?maloaitintuc=1&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="?maloaitintuc=1&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?maloaitintuc=1&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current" ><a href="?maloaitintuc=1&start='.$page.'">'.$page.'</a></li>';  
            }
       $content.=' </ul>
       </div> </div>
    ';  
   
if(isset($_GET['mode']) && $_GET['mode']=='detail'){
    $maloaitintuc=$_GET['maloaitintuc'];
    $matintuc=$_GET['matintuc'];
    $sql='select * from tbl_tin_tuc where id='.$matintuc;
    $kq=tep_db_query($sql);
    $item=tep_db_fetch_array($kq);
    
    $content='
        <div id="center">
       
            <div class="tin_tuc_noi_bat">
                <div class="tieude_center" id="tieude_donvi_center"><h3>Tin Chính</h3></div>
                <div class="hienthi_tt1">
                    <div class="noidung_cb">'.$item['mo_ta_chi_tiet'].'</div>
                </div>
                <div class="tincungchude"><p style="font-weight: bold; text-transform: capitalize; font-size: 13px; color: #0485eb; margin-left:25px; margin-top:10px;">Các Loại Tin Tức Khác:</p></div>';
            
       $sql3='select * from tbl_tin_tuc where ma_loai_tin_tuc=1 and id!='.$matintuc;
       $kq3=tep_db_query($sql3);
       while($item1=tep_db_fetch_array($kq3)){
            $content.='<div class="tincungchude">
            <p style="margin-left:40px; text-transform: capitalize; margin-top:10px; "><a style="text-decoration: none; " href="?page=tintuc&matintuc='.$item['id'].'&maloaitintuc=1&mode=detail">'.$item1['tieu_de_tin_tuc'].'</a><p></div>';
       }
        
   $content.='</div>
     </div>
    ';  
}

echo $content;


?>